//
//  CTTableViewController.m
//  jdforme
//
//  Created by leo on 2017/5/18.
//  Copyright © 2017年 leojingdong.com. All rights reserved.
//

#import "CTTableViewController.h"
#import "CTNavViewController.h"
#import "CTHomeViewController.h"
#import "CTCategoryViewController.h"
#import "CTDiscoverViewController.h"
#import "CTCartTableViewController.h"
#import "CTMyJDViewController.h"
@interface CTTableViewController ()
@property (nonatomic, strong) NSMutableArray *tabbarItems;
@end

@implementation CTTableViewController

#pragma mark - 懒加载
- (NSMutableArray *)tabbarItems {
    if (_tabbarItems == nil) {
        _tabbarItems = [NSMutableArray array];
    }
    return _tabbarItems;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addChildViewControllers];
}
#pragma mark - 添加子控制器
- (void)addChildViewControllers {
    //首页
    CTHomeViewController *homeVc = [[CTHomeViewController alloc] init];
    [self addOneChildViewController:homeVc normalImage:[UIImage imageNamed:@"tabBar_home_normal"] highLightImage:[UIImage imageNamed:@"tabBar_home_press"] navigationBarTitle:@""];
    //分类
    CTCategoryViewController *categoryVc = [[CTCategoryViewController alloc] init];
    [self addOneChildViewController:categoryVc normalImage:[UIImage imageNamed:@"tabBar_category_normal"] highLightImage:[UIImage imageNamed:@"tabBar_category_press"] navigationBarTitle:@""];
    //发现
    CTDiscoverViewController *discoverVc = [[CTDiscoverViewController alloc] init];
    [self addOneChildViewController:discoverVc normalImage:[UIImage imageNamed:@"tabBar_find_normal"] highLightImage:[UIImage imageNamed:@"tabBar_find_press"] navigationBarTitle:@"发现"];
    //购物
    CTCartTableViewController *cartVc = [[CTCartTableViewController alloc] init];
    [self addOneChildViewController:cartVc normalImage:[UIImage imageNamed:@""] highLightImage:[UIImage imageNamed:@""] navigationBarTitle:@"购物车"];
    //我的
    CTMyJDViewController *myJDVc = [[CTMyJDViewController alloc] init];
    [self addOneChildViewController:myJDVc normalImage:[UIImage imageNamed:@""] highLightImage:[UIImage imageNamed:@""] navigationBarTitle:@"我的京东"];
    
    
    
}

#pragma mark - 添加一个子控制器
- (void)addOneChildViewController:(UIViewController *)viewController normalImage:(UIImage *)normalImage highLightImage:(UIImage *)highLightImage navigationBarTitle:(NSString *)title {
    viewController.navigationItem.title = title;
    viewController.tabBarItem.image = normalImage;
    viewController.tabBarItem.selectedImage = highLightImage;
    //添加子控制器到导航控制器
    CTNavViewController *navigationVc = [[CTNavViewController alloc] initWithRootViewController:viewController];
    [self addChildViewController:navigationVc];
    [self.tabbarItems addObject:viewController.tabBarItem];
}


@end
